package cn.heygod.airsql.util;

/**
 * @className: StringUtil
 * @author: Simon
 * @description: TODO
 * @date: 2024/1/27 1:49
 * @version: 1.0
 */
public class StringUtil {

    /**
     * 驼峰转下划线
     * @param camelCase
     * @return
     */
    public static String camelCaseToSnakeCase(String camelCase) {
        return camelCase.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
    }
    /**
     * 下划线转驼峰
     * @param snakeCase
     * @return
     */
    public static String snakeCaseToCamelCase(String snakeCase) {
        StringBuilder camelCase = new StringBuilder();
        boolean nextUpperCase = false;

        for (int i = 0; i < snakeCase.length(); i++) {
            char currentChar = snakeCase.charAt(i);

            if (currentChar == '_') {
                nextUpperCase = true;
            } else {
                if (nextUpperCase) {
                    camelCase.append(Character.toUpperCase(currentChar));
                    nextUpperCase = false;
                } else {
                    camelCase.append(currentChar);
                }
            }
        }

        return camelCase.toString();
    }

}
